package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exception.LyException;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**

 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper,SpecParam>implements SpecParamService {

    @Override
    public List<SpecParamDTO> querySpecparams(Long cid, Long gid) {

        List<SpecParam> list = this.query()
                .eq(null != cid, "category_id", cid)
                .eq(null != gid, "group_id", gid)
                .list();
        return SpecParamDTO.convertEntityList(list);
    }


    @Override
    public void addSpecParam(SpecParamDTO specParamDTO) {
        boolean add = this.save(specParamDTO.toEntity(SpecParam.class));
        if (!add) {
            throw new LyException(500, "添加失败!");
        }
    }

    @Override
    public void updateSpecParam(SpecParamDTO specParamDTO) {
        boolean update = this.updateById(specParamDTO.toEntity(SpecParam.class));
        if (!update) {
            throw new LyException(500, "修改失败!");
        }
    }
}
